package logic

import (
	"context"
	"fmt"
	"house/models/mysql"
	"strings"

	"house/houserpc/houserpc"
	"house/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ConsultAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewConsultAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ConsultAddLogic {
	return &ConsultAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ConsultAddLogic) ConsultAdd(in *houserpc.ConsultAddRequest) (*houserpc.ConsultAddResponse, error) {
	// todo: add your logic here and delete this line
	if strings.Contains(in.Problem, "中介费") || strings.Contains(in.Problem, "虚假") {
		return nil, fmt.Errorf("包含敏感词，请重新输入")
	}

	consult := mysql.Consult{
		UserId:  int(in.UserId),
		HouseId: int(in.HouseId),
		Problem: in.Problem,
	}
	mysql.DB.Debug().Create(&consult)
	return &houserpc.ConsultAddResponse{
		ConsultId: int64(consult.ID),
	}, nil
}
